package com.wits.qso.service;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import com.wits.platform.common.utils.FileUtil;
import com.wits.platform.service.BaseService;
import com.wits.qso.dao.AttachmentDao;
import com.wits.qso.entity.Attachment;

@Component
public class AttachmentService extends BaseService<Attachment, String> {

	private AttachmentDao attachmentDao;

	@Resource
	public void setAttachmentDao(AttachmentDao attachmentDao) {
		this.baseDao = attachmentDao;
		this.attachmentDao = attachmentDao;
	}

	public int deleteByBusinessId(String businessId) {
		return attachmentDao.deleteByBusinessId( businessId );
	}
	
	public List<Attachment> bulkSave(List<Attachment> entites){
		return attachmentDao.bulkSave(entites);
	}
	
	public int bulkUpdate(List<Attachment> entites){
		return attachmentDao.bulkUpdate(entites);
	}
	
	
	public void save(Attachment entity, MultipartFile file,String path,String newName) throws IOException{
		attachmentDao.save(entity); 
    	FileUtil.upload(file,path,newName);
	}

	public List<Attachment> findByBusiness(String bId, String bType) {
		return attachmentDao.findByBusinessIdAndBusinessType(bId, bType);
	}
	
	public List<Attachment> findByBusinessIdAndType(String businessId,
			String businessType){
		return attachmentDao.findByBusinessIdAndBusinessType(businessId, businessType);
	}
	
	public int deleteById(String id) {
		return attachmentDao.deleteById( id );
	}
}
